<?php
namespace app\api\controller;

use app\common\controller\Base;
use app\common\exception\ParameterException;
use app\common\logic\MemberBonusDetail as MemberBonusDetailLogic;
use think\Loader;
use think\Request;


/**
 * @title 内部员工分红记录模块接口
 * @description 接口说明
 * @group 接口分组
 * @header name:token require:1 default: desc:token
 * @param name:user_type type:int require:1 default:1 other: desc:状态(1.会员登陆，2.商家，3.代理商，4.省级代理商，5.内部员工)
 */
class Memberbonusdetail extends Base
{
    /**
     * @title 内部员工分红记录
     * @description 接口说明
     * @author WCJ
     * @url /api/Memberbonusdetail/getBonusDetail
     * @method POST
     * @param name:start type:int require:1 default:1 other: desc:开始数
     * @param name:num type:int require:1 default:1 other: desc:数量
     * @param name:start_time type:int require:0 default:1 other: desc:开始时间
     * @param name:end_time type:int require:0 default:20 other: desc:结束时间
     *
     * @return id: 自增ID
     *
     *
     */
    public function getBonusDetail(Request $request){
        $userid = $this->uid;
        $user_type=$this->type;
        if($user_type!=5){
            $ret=['code' => 201,'errorCode' => 404, 'msg' => '非法操作，非内部员工会员'];
            throw new ParameterException($ret);
        }

        $start_time = $request->post("start_time");
        $end_time = $request->post("end_time");
        $start = $request->post('start') ? $request->post('start') : 0;
        $num = $request->post('num') ? $request->post('num') : 20;
        $validate = Loader::validate("Common");

        if (!$validate->scene("date")->check(['date' => $start_time])) {

            $ret=['code' => 201,'errorCode' => 400, 'msg' => $validate->getError()];
            throw new ParameterException($ret);

        }
        if (!$validate->scene("date")->check(['date' => $end_time])) {

            $ret=['code' => 201,'errorCode' => 400, 'msg' => $validate->getError()];
            throw new ParameterException($ret);

        }
        $memberBonusDetailLogic=new MemberBonusDetailLogic();
        $data=$memberBonusDetailLogic->get_bonus_list($userid,$start_time,$end_time,$start,$num);

        $datas= ["code"=>200,"msg"=>"成功","data"=>$data];
        if($this->new_token){
            $datas["new_token"]=$this->new_token;
        }
        return $datas;

    }

}